var thrift = require('thrift');

//引入hello服务定义文件在同一路径下也要加 ./

var UserManager = require('./gen-nodejs/HelloWorldService.js'),

ttypes = require('./gen-nodejs/demoHello_types.js');

//创建连接和客户端
/*
var connection = thrift.createConnection('localhost', 8085),*/

/*client = thrift.createClient(UserManager, connection);

//连接

connection.on('error', function(err) {

console.error(err);

});
console.log(client.sayHello("1111",function(err, response){
	console.log(response);
}));*/


let server = thrift.createServer(UserManager, {
  sayHello(name, callback){
    callback(null, 'Hello ' + name);
  }

}, {});

server.listen(8085);
server.on('error', console.error);

server.on('listening', () => {

  let conn = thrift.createConnection('127.0.0.1', 8085);
  let client = thrift.createClient(Hello, conn);
  
  client.sayHello('Thrift', console.log);
  // null 'Hello Thrift'
});



//var user =  ttypes.sayHello("1111");

/*var user = new ttypes.User({userId :123,  // 封装类型对象，
	name: "wangyan",
	email: "12323@qq.com",
	address: "dfkjdfkdf",
	phoneNum : 12323});*/
//调用helloString函数;


/*console.log(client.addUser(user,function(err, response){
	console.info(response);
}));*/